package com.namecard.namecardapi.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.namecard.namecardapi.entity.DTO.SpecialOrderDTO;
import com.namecard.namecardapi.entity.SpecialOrder;
import com.namecard.namecardapi.mapper.SpecialOrderMapper;
import com.namecard.namecardapi.service.SpecialOrderService;
import com.namecard.namecardapi.util.SnowflakeIdGenerator;
import org.springframework.stereotype.Service;

@Service
public class SpecialOrderServiceImpl extends ServiceImpl<SpecialOrderMapper, SpecialOrder> implements SpecialOrderService {

    SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(1, 1);

    @Override
    public String createSpecialOrder(String userId, SpecialOrderDTO specialOrderDTO) {
        SpecialOrder specialOrder = new SpecialOrder();
        specialOrder.setOrderId(snowflakeIdGenerator.nextId());
        specialOrder.setUserId(userId);
        specialOrder.setTagDetail(JSON.toJSONString(specialOrderDTO.getTagDetail()));
        specialOrder.setTargetDetail(JSON.toJSONString(specialOrderDTO.getTargetDetail()));
        specialOrder.setTargetEmail(specialOrderDTO.getTargetEmail());
        save(specialOrder);
        return null;
    }
}
